package cn.com.nes.site.controller.crm.customer;

import cn.com.nes.mybatis.agent.crm.entity.CustomerHouse;
import cn.com.nes.site.controller.crm.customer.vo.CustomerHouseSaveVO;
import cn.com.nes.site.entity.PageData;
import cn.com.nes.site.entity.vo.NullVO;
import cn.com.nes.site.entity.vo.crm.DelCustomerHouseInfoVO;
import cn.com.nes.site.entity.vo.crm.GetCustomerHouseDetailVO;
import cn.com.nes.site.entity.vo.crm.GetCustomerHousePageVO;
import cn.com.nes.site.service.crm.customer.CustomerHouseService;
import cn.com.nes.site.service.crm.customer.dto.HouseDTO;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 客户房屋控制层
 *
 * @Author: ShenWei
 * @Date: 2024/07/23/10:55
 */
@Api(tags = {"销售管理-客户管理-房屋管理"})
@Controller
@RequestMapping("/v2/crm/customer/house")
public class CustomerHouseController {

    @Resource
    private CustomerHouseService customerHouseService;

    @ApiOperation(value = "查询房屋信息分页")
    @RequestMapping(value = "/getHousePage", method = RequestMethod.GET)
    public @ResponseBody PageData getHousePage(@Validated GetCustomerHousePageVO vo) throws Exception {
        Page<HouseDTO> housePage = customerHouseService.getHousePage(vo.convertToBo());
        return PageData.ok(housePage, housePage.getRecords());
    }

    @ApiOperation(value = "查询客户房屋详情")
    @RequestMapping(value = "/getHouseDetail", method = RequestMethod.GET)
    public @ResponseBody PageData getHouseDetail(@Validated GetCustomerHouseDetailVO vo) throws Exception {
        return PageData.ok("houseDetail", customerHouseService.getHouseDetail(vo.getHouseUuid()));
    }

    @ApiOperation(value = "保存房屋信息")
    @RequestMapping(value = "/saveHouse", method = RequestMethod.POST)
    public @ResponseBody PageData saveHouse(@RequestBody @Validated CustomerHouseSaveVO vo) throws Exception {
        CustomerHouse customerHouse = customerHouseService.saveCustomerHouse(vo.convertToBo());
        return PageData.ok("houseUuid", customerHouse.getHouseUuid());
    }

    @ApiOperation(value = "删除房屋信息")
    @RequestMapping(value = "/delHouseInfo", method = RequestMethod.POST)
    public @ResponseBody PageData delHouseInfo(@RequestBody @Validated DelCustomerHouseInfoVO vo) throws Exception {
        return customerHouseService.delHouseInfo(vo);
    }

    @ApiOperation("相关下拉框")
    @RequestMapping(value = "/saveHouseDropdownBox", method = RequestMethod.GET)
    public @ResponseBody PageData saveHouseDropdownBox(NullVO vo) throws Exception {
        return customerHouseService.saveHouseDropdownBox(vo);
    }

}
